﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows;
using System.Windows.Forms.Integration;

namespace Renci.iRods.Studio.Modules.Explorer.Controls
{
    public class PropertyGrid : ContentControl
    {
        public PropertyGrid()
        {
        }

        public object SelectedObject
        {
            get { return (object)GetValue(SelectedObjectProperty); }
            set { SetValue(SelectedObjectProperty, value); }
        }

        // Using a DependencyProperty as the backing store for SelectedObject.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty SelectedObjectProperty = DependencyProperty.Register("SelectedObject", typeof(object), typeof(PropertyGrid));

        protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
        {
            base.OnPropertyChanged(e);

            if (e.Property.Name == PropertyGrid.SelectedObjectProperty.Name)
            {
                var pg = new System.Windows.Forms.PropertyGrid() { SelectedObject = e.NewValue };
                WindowsFormsHost wfh = new WindowsFormsHost() { Child = pg };
                this.Content = wfh;
            }
        }
    }
}
